using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using Backend.JYD.Model.Cust;

namespace Backend.JYD.EFDAL.Mapping
{
    public class CustAddressMap : EntityTypeConfiguration<CustAddress>
    {
        public CustAddressMap()
        {
            // Primary Key
            this.HasKey(t => new { t.CustNo, t.Province, t.City, t.Address, t.IsDefault });

            // Properties
            this.Property(t => t.CustNo)
                .IsRequired()
                .HasMaxLength(20);

            this.Property(t => t.Province)
                .IsRequired()
                .HasMaxLength(20);

            this.Property(t => t.City)
                .IsRequired()
                .HasMaxLength(20);

            this.Property(t => t.Region)
                .HasMaxLength(20);

            this.Property(t => t.Address)
                .IsRequired()
                .HasMaxLength(200);

            this.Property(t => t.PostCode)
                .IsFixedLength()
                .HasMaxLength(10);

            // Table & Column Mappings
            this.ToTable("CustAddress");
            this.Property(t => t.CustNo).HasColumnName("CustNo");
            this.Property(t => t.Province).HasColumnName("Province");
            this.Property(t => t.City).HasColumnName("City");
            this.Property(t => t.Region).HasColumnName("Region");
            this.Property(t => t.Address).HasColumnName("Address");
            this.Property(t => t.PostCode).HasColumnName("PostCode");
            this.Property(t => t.IsDefault).HasColumnName("IsDefault");
            this.Property(t => t.Status).HasColumnName("Status");
            this.Property(t => t.Type).HasColumnName("Type");
            this.Property(t => t.CreateTime).HasColumnName("CreateTime");
            this.Property(t => t.UpdateTime).HasColumnName("UpdateTime");
            this.Property(t => t.OpId).HasColumnName("OpId");

            // Relationships
            this.HasRequired(t => t.CustBaseInfo)
                .WithMany(t => t.CustAddresses)
                .HasForeignKey(d => d.CustNo);
        }
    }
}
